package com.bringway.p2p.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.bringway.framework.controller.JsonController;
import com.bringway.framework.util.RequestUtils;
import com.bringway.p2p.service.P2PCustomerService;

import net.sf.json.JSONObject;

/*
 * @author fan
 * @className P2PCustomerController
 * @date 2016年1月28日上午11:52:57
 */
@Controller
@RequestMapping("/customer")
public class P2PCustomerController extends JsonController{
	@Resource
	private P2PCustomerService p2pCustomerService;
	/**
	 * @方法名称:feedback
	 * @author fan
	 * @date 2016年1月28日上午11:57:07
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping("/feedback")
	public ModelAndView feedback(HttpServletRequest request ,HttpServletResponse response) throws Exception{
		
		String ADVICE_START_DATE = RequestUtils.getStringParameter(request,"ADVICE_START_DATE");
		String ADVICE_END_DATE = RequestUtils.getStringParameter(request, "ADVICE_END_DATE");
		String USER_ID = RequestUtils.getStringParameter(request, "USER_ID");
		String LXFS = RequestUtils.getStringParameter(request, "LXFS");
		String DEVICE_TYPE = RequestUtils.getStringParameter(request,"DEVICE_TYPE");
		Integer page = RequestUtils.getIntParameter(request, "page");//新版本,传参
		Integer start =RequestUtils.getIntParameter(request, "start");
		Integer limit = RequestUtils.getIntParameter(request, "limit");
		if (null!=page) {//新版本,传参
			start=(page-1)*limit;
		}
		JSONObject parms = new JSONObject();
		parms.put("ADVICE_START_DATE",ADVICE_START_DATE);
		parms.put("ADVICE_END_DATE",ADVICE_END_DATE);
		parms.put("USER_ID",USER_ID);
		parms.put("LXFS",LXFS);
		parms.put("DEVICE_TYPE",DEVICE_TYPE);
		parms.put("start", start);
		parms.put("limit", limit);
		List list= p2pCustomerService.getCustomerFeedBackInfo(parms);
		System.out.println(list);
		System.out.println(parms);
		int total = p2pCustomerService.getPageCount(parms);
		JSONObject result = new JSONObject();
		result.put("data", list);
		result.put("total", total);
		if (null!=page) {//新版本,传参
			int totalPage=total%limit==0?total/limit:total/limit+1;
			result.put("totalPage", totalPage);
		}
		serialize(request, response, result);
		return null;
	}
}
